package com.pandy.juc;

/**
 * volatile保证可见性
 */
public class Code01_VolatileDemo {

    private static volatile boolean stop = false;

    public static void main(String[] args) throws InterruptedException {
        new Thread(() -> {
            while (!stop) { }
            System.out.println("线程退出");
        }).start();


        Thread.sleep(1000);
        // 主线程修改stop值
        stop = true;
    }
}
